package io.gitee.macxiang.component;

import java.net.Inet4Address;

import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class ServerPortListener implements ApplicationListener<WebServerInitializedEvent> {
  @Override
  public void onApplicationEvent(WebServerInitializedEvent event) { // 开机打印本机IP:端口
    final String format = "http://%s:" + event.getWebServer().getPort();
    try {
      System.out.println(String.format(format, Inet4Address.getLocalHost().getHostAddress()));
    } catch (Exception e) {
    }
    System.out.println(String.format(format, "localhost"));
  }

}